<template>
  <el-dialog
    :top="ptop"
    :close-on-click-modal="false"
    class="publicDialog"
    :visible.sync="innerVisible"
    v-bind="$attrs"
    :before-close="handleCencel"
  >
    <slot></slot>
    <span slot="footer" class="dialog-footer">
      <template v-if="!hasSlot">
        <el-button size="small" type="primary" @click="handleConfirm">{{BtnTitleL}}</el-button>
        <el-button size="small" @click="handleCencel">{{BtnTitleR}}</el-button>
      </template>
      <slot v-else name="diafooter"></slot>
    </span>
  </el-dialog>
</template>

<script>
export default {
  model: {
    prop: 'dialogVisible',
    event: 'toggle'
  },
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    BtnTitleL:{
      type:String,
      default:"确定"
    },
    BtnTitleR:{
      type:String,
      default:"取消"
    },
    ptop:{
      type:String,
      default:"10%"
    }
  },
  computed: {
    innerVisible: {
      get: function () {
        return this.dialogVisible;
      },
      set: function (val) {
        this.$emit('update:toggle', val);
      },
    },
    hasSlot() {
      return !!this.$slots.diafooter;
    },
  },
  methods: {
    handleConfirm() {
      this.$emit("comfirm");
    },
    handleCencel() {
      this.$emit("cencel");
    },
  },
};
</script>

<style scoped lang="less">
.publicDialog {
  /deep/.el-dialog {
    // border-radius: 8px;
    overflow: hidden;
    .el-dialog__header {
      padding: 10px 20px;
      background-color: #0871e8;
      .el-dialog__title{
        font-weight: 650;
        font-size: 14px;
        color: #FFFFFF;
        text-align: left;
        // line-height: 22px;
      }
      .el-dialog__headerbtn {
        top: 10px;
        .el-dialog__close{
          color:#FFFFFF;
          font-size: 25px;
        }
      }
    }
    .el-dialog__body {
      padding: 20px;
    }
    .el-dialog__footer {
      display: flex;
      justify-content: center;
    }
  }
}
</style>